package ru.simplemaps.osmapi.objects;

import java.util.Collection;
import java.util.TreeSet;

/**
 * @author enaku_adm
 * @since 22.07.2010 11:11:43
 */
public class Way extends AbstractOSMElement {
    public Way(long id) {
        super(id, OSMElementType.way);
    }

    public final Collection<NodeRef> nodes = new TreeSet<NodeRef>();

    public final void addNode(long nodeId) {
        nodes.add(new NodeRef(nodeId, nodes.size()));
    }

    public static class NodeRef implements Comparable<NodeRef> {
        public final long ref;
        private final int pos;

        public NodeRef(long ref, int pos) {
            this.ref = ref;
            this.pos = pos;
        }

        public int compareTo(NodeRef o) {
            return (pos < o.pos ? -1 : (pos == o.pos ? 0 : 1));
        }
    }

    @Override
    public boolean equalsFull(Object o) {
        boolean superVal = super.equalsFull(o);
        if (!superVal) return false;
        
        Way other = (Way) o;
        return other.nodes.equals(nodes);
    }
}
